﻿@model SCM.Model.DBEntity.T_Material_Parts
@{
    Layout = null;
}
<div class="home-desktop">
    <div class="content-pages-title">
        <h1>编辑零件</h1>
    </div>
    <div class="content-notice-body">
        <!--基本信息-->
        <div class="modular-modular" style="display: block;">
            <form action="@(Url.Action("Modify"))" method="post" id="form-edit-materialParts">
                <table style="width: 100%; border: none;">
                    <tr>
                        <td valign="top">
                            <div class="notice-box-left">
                                <div class="modular-info" style="display: block;">
                                    <ul class="form">
                                        <li>
                                            <em>零件编码</em>
                                            <input type="text" value="@Model.PartCode" name="partCode" maxlength="50" required />
                                        </li>
                                        <li>
                                            <em>零件名称</em>
                                            <input type="text" value="@Model.PartName" name="partName" maxlength="200" required />
                                        </li>
                                        <li>
                                            <em>供应商</em>
                                            <input type="text" id="txtSupplier" value="@Model.SupplierName" placeholder="请选择供应商" readonly="readonly" />
                                            <input type="hidden" id="hdSupplierId" name="supplierID" value="@Model.SupplierID" />
                                        </li>
                                        <li>
                                            <em>绿色认证状态</em>
                                            <select asp-items="@Html.GetEnumItemList(typeof(GreenStatusEnum))" asp-for="GreenStatus"></select>
                                        </li>
                                        <li class="row-last">
                                            <em>&nbsp;</em>&nbsp;&nbsp;
                                            <button type="button" class="cotrlBtn btnBlue" id="btn_save">保存</button>
                                        </li>
                                    </ul>
                                    <input type="hidden" id="hdMainID" name="id" value="@Model.ID" />
                                </div>
                            </div>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    //保存基本信息
    $("#btn_save").click(function () {
        if ($('#form-edit-materialParts').valid()) {
            $("#form-edit-materialParts").ajaxSubmit({
                datatype: "json",
                data: $('#form-edit-materialParts').serialize(),
                success: function (result) {
                    if (result.code == 0) {
                        $("#hdMainID").val(result.data);
                        dcAlert(result.message, 0, 1, function () {
                            $(".layer-dialog-close-btn").click();
                            //刷新显示数据
                            btn_search_click();
                        });
                    }
                    else {
                        dcAlert(result.message, 0, 2);
                    }
                }
            });
        }
    });

    //选择供应商
    $('#txtSupplier').click(function () {
        layer.open({
            type: 2,
            title: "选择供应商",
            shadeClose: true,
            shade: 0.4,
            area: ['80%', '90%'],
            offset: ['5%', '10%'],
            content: "@Url.Action("SelectView", "BasicSupplier")",
            btn: ['确定', '关闭'],
            yes: function (index) {
                //当点击‘确定’按钮的时候，获取弹出层返回的值
                var selectRows = window["layui-layer-iframe" + index].callbackdata();
                //打印返回的值，看是否有我们想返回的值。
                if (selectRows == "" || selectRows.length != 1) {
                    dcAlert("请选择一条数据", 0, 2);
                    return false;
                }
                var dataArray = selectRows[0].split('|');

                $("#hdSupplierId").val(dataArray[0]);
                $("#txtSupplier").val(dataArray[1]);

                //最后关闭弹出层
                layer.close(index);
            },
            cancel: function () {
                //右上角关闭回调
            }
        });
    });
</script>
